package net.es.weathermap.metric;

import java.util.Map;

import net.es.oscars.client.improved.ConfigHelper;
import net.es.weathermap.beans.Domain;

public class MetricProviderFactory {
    private static final String DEFAULT_INFO_FILE = "network.yaml";
    private static Map config = null;
    private static String resvMP;
    private static String utilMP;

    public static MetricProvider getResvMP(Domain dom) {
        if (config == null) {
            configure();
        }
        if (resvMP.equals("OscarsMP")) {
            OscarsMP mp = OscarsMP.getInstance(dom);
            return mp;
        }
        return null;

    }

    public static MetricProvider getUtilMP(Domain dom) {
        if (config == null) {
            configure();
        }
        if (utilMP.equals("ESnetMP")) {
            ESnetMP mp = ESnetMP.getInstance(dom);
            return mp;
        }
        return null;
    }

    private static void configure() {
        ConfigHelper cfg = ConfigHelper.getInstance();
        config = cfg.getConfiguration(DEFAULT_INFO_FILE);
        assert config != null:  "Could not load soap configuration file from " +
            "file: ${basedir}/config/" + DEFAULT_INFO_FILE;
        Map metricProviders = (Map) config.get("metricProviders");
        resvMP = (String) metricProviders .get("resv");
        utilMP = (String) metricProviders .get("util");
    }
}
